Expand description
§NovaX Crate
novax
is a Rust crate dedicated to generating clients at compile time to interact with smart contracts on a blockchain.
The crate automatically generates necessary structures and methods from ABIs (Application Binary Interface) to provide a seamless and type-safe way to interact with smart contracts.
The crate’s functionality is driven by the environment variable NOVAX_PATH
which should point to a directory containing a sub-directory named abis
where the ABIs are located.
§Setup
To use novax
, set up the environment variable NOVAX_PATH
in your .cargo/config.toml
file as follows:
[env]
NOVAX_PATH={ value = ".novax", relative = true }
Here, .novax
is a folder at the project’s root containing a sub-directory named abis
where the ABIs are placed.
§Modules
caching
: Provides caching strategies to optimize smart contract queries.errors
: Centralized module for handling various error types encountered within thenovax
crate’s operations.transaction
: Contains essential structs and types for handling blockchain transactions.code
: Facilitates reading and handling of smart contract code.account
: Provides structures and functionalities for handling and obtaining account information.
The crate also includes a generated module from a file in the OUT_DIR
directory, which contains structures and methods derived from the ABIs.
§Key Features
CachingStrategy
andCachingNone
: Facilitate caching behavior during query operations, defined in thecaching
module.CallResult
andTokenTransfer
: Handle transaction responses and token transfers respectively, located in thetransaction
module.AsBytesValue
,FileCode
, andDeployData
: Essential for handling smart contract code and deployment data, defined in thecode
module.AccountInfos
andfrom_address
function: Assist in obtaining and handling account-related information, found in theaccount
module.- Error Handling: Various error types such as
CodeError
,CachingError
,AccountError
, andDateError
are defined in theerrors
module to cover different error scenarios.
§Usage
Once the NOVAX_PATH
environment variable is set up and the ABIs are placed in the specified directory,
the novax
crate automatically generates the required client code when the project is built.
This generated code can then be used to interact with the smart contracts as per the methods and structures defined in the ABIs.
§Compile-Time Code Generation
The novax
crate utilizes Rust’s procedural macro facilities to perform code generation at compile time.
This ensures that the generated code is type-safe, efficient, and ready-to-use right out of the box.
Modules§
- The
account
module provides structures and functionalities for handling and obtaining account information. - The
caching
module provides caching strategies to optimize smart contract queries. - The
code
module facilitates reading and handling of smart contract code. - The
data
module provides re-exports of functionalities from thenovax_data
crate. - The
errors
module centralizes various error types encountered within thenovax
crate’s operations. - The
executor
module provides re-exports of functionalities from thenovax_executor
crate. - The
transaction
module contains essential structs and types for handling blockchain transactions. - The
utils
module provides some helpers to make the framework working.
Structs§
- A struct representing a blockchain address. This struct provides various utility methods for working with addresses, including conversions from and to Bech32 string representations and byte arrays.